﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Fin;
using nERP.Model;
using nERP.Model.Po;

namespace nERP.ViewModel.Fin.PaymentDetailVMs
{
    public partial class PaymentDetailListVM : BasePagedListVM<PaymentDetail_View, PaymentDetailSearcher>
    {

        protected override IEnumerable<IGridColumn<PaymentDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<PaymentDetail_View>>{

                this.MakeGridHeader(x => x.PaymentDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Pay).SetTitle(@Localizer["Page.付款单"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_PayDetailCode).SetTitle(@Localizer["Page.付款明细单号"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Buy).SetTitle(@Localizer["Page.采购订单"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Amount1).SetTitle(@Localizer["Page.单据金额"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Amount2).SetTitle(@Localizer["Page.已结金额"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Amount3).SetTitle(@Localizer["Page.未结金额"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Amount4).SetTitle(@Localizer["Page.本次结算金额"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.PaymentDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }


        public override IOrderedQueryable<PaymentDetail_View> GetSearchQuery()
        {
            var query = DC.Set<PaymentDetail>()

                .CheckEqual(Searcher.Seq, x => x.Seq)
                .CheckEqual(Searcher.PayId, x => x.PayId)
                .CheckContain(Searcher.PayDetailCode, x => x.PayDetailCode)
                .CheckEqual(Searcher.BuyId, x => x.BuyId)
                .CheckEqual(Searcher.Amount1, x => x.Amount1)
                .CheckEqual(Searcher.Amount2, x => x.Amount2)
                .CheckEqual(Searcher.Amount3, x => x.Amount3)
                .CheckEqual(Searcher.Amount4, x => x.Amount4)
                .CheckContain(Searcher.Remark, x => x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                .Select(x => new PaymentDetail_View
                {
                    ID = x.ID,

                    PaymentDetail_Seq = x.Seq,
                    PaymentDetail_Pay = DC.Set<Payment>().Where(z0 => z0.PayCode == x.PayId).Select(y => y.PayCode).FirstOrDefault(),
                    PaymentDetail_PayDetailCode = x.PayDetailCode,
                    PaymentDetail_Buy = DC.Set<Buy>().Where(z0 => z0.BuyCode == x.BuyId).Select(y => y.BuyCode).FirstOrDefault(),
                    PaymentDetail_Amount1 = x.Amount1,
                    PaymentDetail_Amount2 = x.Amount2,
                    PaymentDetail_Amount3 = x.Amount3,
                    PaymentDetail_Amount4 = x.Amount4,
                    PaymentDetail_Remark = x.Remark,
                    PaymentDetail_Status = x.Status,
                    PaymentDetail_CreateTime = x.CreateTime,
                    PaymentDetail_UpdateTime = x.UpdateTime,
                    PaymentDetail_CreateBy = x.CreateBy,
                    PaymentDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }


    }
    public class PaymentDetail_View : PaymentDetail
    {

        public int? PaymentDetail_Seq { get; set; }
        public string PaymentDetail_Pay { get; set; }
        public string PaymentDetail_PayDetailCode { get; set; }
        public string PaymentDetail_Buy { get; set; }
        public decimal? PaymentDetail_Amount1 { get; set; }
        public decimal? PaymentDetail_Amount2 { get; set; }
        public decimal? PaymentDetail_Amount3 { get; set; }
        public decimal? PaymentDetail_Amount4 { get; set; }
        public string PaymentDetail_Remark { get; set; }
        public dStatusTypeEnum? PaymentDetail_Status { get; set; }
        public DateTime? PaymentDetail_CreateTime { get; set; }
        public DateTime? PaymentDetail_UpdateTime { get; set; }
        public string PaymentDetail_CreateBy { get; set; }
        public string PaymentDetail_UpdateBy { get; set; }

    }

}